package com.aqie.arithmetic.datastructure;

/**
 * quick-find
 */
public abstract class UFBase {
    // 分量id
    protected int[] id;
    // 分量数量
    protected int count;

    // 初始化分量ID数组
    public UFBase(int N){
        count = N;
        id = new int[N];
        for (int i = 0; i < N; i++){
            id[i] = i;
        }
    }

    public int getCount(){
        return count;
    }

    public boolean connected(int p, int q){
        return find(p) == find(q);
    }


    protected abstract int find(int p);
}
